#ifndef CONFIGCTL_H
#define CONFIGCTL_H

#include <QComboBox>
#include <QLineEdit>
#include <QPushButton>
#include <QTextEdit>
#include <QWidget>

#include <map>
#include <string>
#include <vector>

#include "node/node.h"

class ConfigCtl : public QWidget {
    Q_OBJECT

  public:
    explicit ConfigCtl(QComboBox *qConfigBox, QComboBox *qConfigValBox, QPushButton *qBtnConfigSubmit,
                       QComboBox *qFreeConfigBox, QLineEdit *qFreeConfigValText, QPushButton *qBtnFreeConfigSubmit,
                       QPushButton *qBtnConfigRefresh, QTextEdit *qConfigResultText, std::shared_ptr<AppNode> appNode_,
                       QWidget *parent = nullptr);
    ~ConfigCtl();

  private slots:
    void onConfigListActivated(const QString &text);
    void onBtnConfigClicked();

    void onFreeConfigListActivated(const QString &text);
    void onBtnFreeConfigClicked();

    void onBtnConfigRefreshClicked();

  private:
    void updateQConfigValBox(const std::string &configName);
    bool updateAllConfigInfo();
    bool updateAllConfigVal();
    void updateConfigVal(const std::string &configName, const std::string &configVal);

  private:
    QComboBox *qConfigBox_;
    QComboBox *qConfigValBox_;
    QPushButton *qBtnConfigSubmit_;
    QComboBox *qFreeConfigBox_;
    QLineEdit *qFreeConfigValText_;
    QPushButton *qBtnFreeConfigSubmit_;
    QPushButton *qBtnConfigRefresh_;
    QTextEdit *qConfigResultText_;

    std::shared_ptr<AppNode> appNode_;

    // 存放选择配置的子项，用于页面更新
    std::map<std::string, std::vector<std::string>> configListMap_;

    // 存放配置当前值，用于页面更新
    std::map<std::string, std::string> currentConfigValMap_;
};

#endif // CONFIGCTL_H
